package edu.famework.demo1;

import java.util.Scanner;

public class Manager {

    private Employee[] emps;
    private int count;

    public Manager(){
        emps= new Employee[3];
    }
    /**
     * 添加员工信息
     * @param employee 员工对象
     */
    public void addEmployee(Employee employee){
        if(employee != null){
            if(count < 3){
                emps[count] = employee;
                count++;
                System.out.println("添加成功了-----");
            }else{
                System.out.println("添加失败了-----");
            }
        }
    }

    /**
     * 根据员工的编号查询某个员工信息
     * 遍历emps数组，每遍历一次就要从数组中获取到对象。判断数组中对象的id是否与用户输入的id相同
     */
    public Employee getQueryById(int id){
        Employee e = null;
        for (int i = 0; i < emps.length; i++) {
            if(emps[i] != null){
                if(emps[i].getId() == id){
                    emps[i]= e;
                    break;
                }
            }
        }
        return e;
    }


    /**
     * 修改员工信息
     * @param
     */

    public Employee updat(Employee employee){
        employee.setName("赵俊鹏");
        return employee;
    }





    /**
     * 查询所有员工信息
     * @param args
     */


    public static void main(String[] args) {
        Manager manager = new Manager();
        Scanner input = new Scanner(System.in);
        for (int i = 0; i < args.length; i++) {
            System.out.println("请输入员工编号");
            int id = input.nextInt();
            System.out.println("请输入员工姓名");
            String  name = input.next();
            System.out.println("请输入员工工资");
            double salary = input.nextDouble();
            System.out.println("请输入员工部门");
            String dept = input.next();

            Employee e = new Employee(id,name,salary,dept);

            //将对象添加到数组中
            manager.addEmployee(e);
        }

        //根据id查询对象
        Employee employee = manager.getQueryById(101);
        if(employee != null){
            System.out.println(employee.getName());
        }else
        {
            System.out.println("error________");
        }

        //调用修改的方法

        Employee e = manager.updat(employee);
        System.out.println(e.getName());
    }
}
